﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Kimd.Communication
{
    public interface ISocketServer : ISocket
    {
        /// <summary>
        /// 客户端
        /// </summary>
        List<TcpClientState> TCPClients { get; }
        /// <summary>
        /// 是否已经服务器打开
        /// </summary>
        bool IsStart { get; }
       /// <summary>
       /// 是否有客户端连接状态
       /// </summary>
        bool IsConnected { get; }
        /// <summary>
        /// 接收信息事件
        /// </summary>
        event EventHandler<TcpServerDatagramReceivedEventArgs<byte[]>> DatagramReceived;

        /// <summary>
        /// 开启服务器
        /// </summary>
        /// <returns></returns>
        bool Start();
        /// <summary>
        /// 关闭服务器
        /// </summary>
        /// <returns></returns>
        bool Close();
        /// <summary>
        /// 发送信息，返回发送状态,接收值
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="data"></param>
        /// <param name="receive"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        bool Send(TcpClient tcpClient, byte[] data, out string receive, int timeout = 500);
        /// <summary>
        /// 发送信息，返回发送状态,接收值
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="data"></param>
        /// <param name="receive"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        bool Send(TcpClient tcpClient, byte[] data, out byte[] receive, int timeout = 500);
        /// <summary>
        /// 发送信息，返回发送状态
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        bool Send(TcpClient tcpClient, byte[] data);
        /// <summary>
        /// 发送信息，返回发送状态,接收值
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="data"></param>
        /// <param name="receive"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        bool Send(TcpClient tcpClient, String data, out string receive, int timeout = 500);
        /// <summary>
        /// 发送信息，返回发送状态,接收值
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="data"></param>
        /// <param name="receive"></param>
        /// <param name="timeout"></param>
        /// <returns></returns>
        bool Send(TcpClient tcpClient, String data, out byte[] receive, int timeout = 500);
        /// <summary>
        /// 发送信息，返回发送状态
        /// </summary>
        /// <param name="tcpClient"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        bool Send(TcpClient tcpClient, String data);
        /// <summary>
        /// 所有客户端发送信息
        /// </summary>
        /// <param name="send"></param>
        /// <returns></returns>
        bool SendAll(String send);
        /// <summary>
        /// 所有客户端发送信息
        /// </summary>
        /// <param name="send"></param>
        /// <returns></returns>
        bool SendAll(byte[] send);

    }
}
